local hx__qiami = fk.CreateSkill {
  name = "hx__qiami",
}



hx__qiami:addEffect(fk.TargetSpecified, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return not target.dead and player:hasSkill(hx__qiami.name) and data.card and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local suits = {}
    local suitid = {}
    for _, cid in ipairs(player.player_cards[Player.Hand]) do
      local card = Fk:getCardById(cid)
      local suitname = card:getSuitString(true)
      if not (suitname == "nosuit" or table.contains(suits, suitname)) then
        table.insert(suits, suitname)
        table.insert(suitid, Fk:getCardById(cid).suit)
      end
    end
    if #suits ~= 0 then
      local choice = room:askToChoice(player, {
        choices = table.connect({"Cancel"}, suits),
        skill_name = hx__qiami.name,
        prompt = "#hx__qiami-choose",
        cancelable = false,
      })
      if choice ~= "Cancel" then
        event:setCostData(self, {suitid = suitid[table.indexOf(suits, choice)]})
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local suit = event:getCostData(self).suitid
    local discard = table.filter(player.player_cards[Player.Hand], function(cid)
      return Fk:getCardById(cid).suit == suit
    end)
    room:throwCard(discard, hx__qiami.name, player, player)
    local x = #discard
    if x > 0 then
      data.use.additionalEffect = (data.use.additionalEffect or 0) + x
    end
  end,
})

return hx__qiami